package org.indexador.util.stax;

import java.util.*;

import javax.xml.stream.*;

/**
 * @author Lara D'Abreo
 * 
 * Common stax utilities.
 *  
 */
public class StaxUtil {
  public static void moveReaderToElement(String target, XMLStreamReader reader)
      throws XMLStreamException, NoSuchElementException {
    for (int event = reader.next(); event != XMLStreamConstants.END_DOCUMENT; event = reader
        .next()) {
      if (event == XMLStreamConstants.START_DOCUMENT) {
        System.out.println("start:" + reader.getName());
      } else if (event == XMLStreamConstants.END_DOCUMENT) {
        System.out.println("end:" + reader.getName());
      } else {
//        System.out.println(reader.getText());
      }
      if ((event == XMLStreamConstants.START_ELEMENT)
          && (reader.getLocalName().equals(target))) {
        return;
      }
    }
  }
}
